]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
dash: Calculate icon size changes without reallocation
authorFlorian Müllner <fmuellner@gnome.org>
Sat, 27 Nov 2010 21:31:14 +0000 (22:31 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 9 Feb 2011 20:36:55 +0000 (21:36 +0100)
The current approach to adjust the icon size of dash items is rather
expensive: the size of each item is changed from largest to smallest,
until the height of the dash fits the maximum available height, so
quite some ClutterTextures are created and disposed.
A better approach is to calculate the required size beforehand and
only change the icon size when necessary.

https://bugzilla.gnome.org/show_bug.cgi?id=636156

js/ui/dash.js

index 86dfacdda7f689910fac1fde11976d7c2306a03c..98133726c9549f48b54a255828e1e1145ca24c75 100644 (file)
@@ -203,9 +203,51 @@ Dash.prototype = {
                                    Lang.bind(this, function() {
                                        display.actor.opacity = 255;
                                    }));
+        display.icon.setIconSize(this._iconSize);
+
         this._box.add(display.actor);
     },
 
+    _adjustIconSize: function() {
+        let children = this._box.get_children();
+        if (children.length == 0) {
+            this._box.add_style_pseudo_class('empty');
+            return;
+        }
+
+        this._box.remove_style_pseudo_class('empty');
+
+        if (this._maxHeight == -1)
+            return;
+
+        let iconChildren = children.filter(function(actor) {
+            return actor.visible && actor._delegate && actor._delegate.icon;
+        });
+
+        // Compute the amount of extra space (or missing space) we have
+        // per icon with the current icon size
+        let [minHeight, natHeight] = this.actor.get_preferred_height(-1);
+        let diff = (this._maxHeight - natHeight) / iconChildren.length;
+
+        let iconSizes = [ 16, 22, 24, 32, 48 ];
+
+        let newIconSize = 16;
+        for (let i = 0; i < iconSizes.length; i++) {
+            if (iconSizes[i] < this._iconSize + diff)
+                newIconSize = iconSizes[i];
+        }
+
+        if (newIconSize == this._iconSize)
+            return;
+
+        this._iconSize = newIconSize;
+
+        for (let i = 0; i < iconChildren.length; i++) {
+            let icon = iconChildren[i]._delegate.icon;
+            icon.setIconSize(this._iconSize);
+        }
+    },
+
     _redisplay: function () {
         this._box.hide();
         this._box.destroy_children();
@@ -229,29 +271,7 @@ Dash.prototype = {
             this._addApp(app);
         }
 
-        let children = this._box.get_children();
-        if (children.length == 0) {
-            this._box.add_style_pseudo_class('empty');
-        } else {
-            this._box.remove_style_pseudo_class('empty');
-
-            if (this._maxHeight > -1) {
-                let iconSizes = [ 48, 32, 24, 22, 16 ];
-
-                for (let i = 0; i < iconSizes.length; i++) {
-                    let minHeight, natHeight;
-
-                    this._iconSize = iconSizes[i];
-                    for (let j = 0; j < children.length; j++)
-                        children[j]._delegate.icon.setIconSize(this._iconSize);
-
-                    [minHeight, natHeight] = this.actor.get_preferred_height(-1);
-
-                    if (natHeight <= this._maxHeight)
-                        break;
-                }
-            }
-        }
+        this._adjustIconSize();
         this._box.show();
     },